<?php
/**
 * Klasse zur Umwandlung von Objekten in Arrays und umgekehrt
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2013 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 *
 * */


Class Yapary_SimpleObject
{


	/**
	* Wandelt ein Objekt in ein Array um
	* @param object $obj : Umzuwandelndes Objekt
	* @return array
	*/
	public function object2Array ( $obj )
	{
		$arr = array();
		if (is_object($obj) && count($obj) >= 1) {
			foreach ($obj as $key => $val){
				if(is_object($val)) {
					$arr[$key] = $this->object2Array($val);
				} else {
					//echo $val;
					$arr[$key] = $val;
				}
			}
		} else {
			$arr[$key] = NULL;
		}

		return $arr;
	}


	/**
	* Wandelt ein Array in ein Objekt
	* @param array $arr : Umzuwandelndes Array
	* @return object
	*/
	public function array2Object ( $arr )
	{
		if (is_array($arr) && count($arr) >= 1) {
			foreach ($arr as $key => $val){
				if(is_array($val)) {
					$arr[$key] = $this->array2Object($val);
				}
			}
		} else {
			$arr = NULL;
		}

		return (object)$arr;
	}


}


/*
$oYapary_SimpleObject = new Yapary_SimpleObject();

$arrTest['first'] = 'a10b';
$arrTest['second']['second2'] = 'c20d';
//$arrTest['second']['second2']['sd'] = 'e40f';
$arrTest['third']['third2']['third3'] = 'g30h';

$obj = $oYapary_SimpleObject->array2Object($arrTest);
//echo $obj->third->third2->third3;

$arr = $oYapary_SimpleObject->object2Array($obj);
$arr['second']['second2'];
*/
?>